//请求获得监测点的坐标，以及属性
//
//路径定义

var fw = [];
function WaterplanHelper() {
	var waterplant = new Object();
	var layerUrl = mapUrl + "/iserver/services/map-HB/rest/maps/zjMap";
	var queryParam = new SuperMap.REST.FilterParameter({
		name: "水厂@HB#1",
		attributeFilter: " "
	});
	var queryBySQLParams = new SuperMap.REST.QueryBySQLParameters({
		queryParams: [queryParam]
	});
	var myQueryBySQLService = new SuperMap.REST.QueryBySQLService(layerUrl, {
		eventListeners: {
			"processCompleted": queryCompleted,
			"processFailed": queryError
		}
	});

	function queryCompleted(queryEventArgs) {
		var i, j, feature,
			result = queryEventArgs.result;
		if (result && result.recordsets) {
			for (i = 0; i < result.recordsets.length; i++) {
				if (result.recordsets[i].features) {
					for (j = 0; j < result.recordsets[i].features.length; j++) {
						feature = result.recordsets[i].features[j];
						var geo = {};
						geo.type = "W";
						geo.x = feature.attributes['SMX'];
						geo.y = feature.attributes['SMY'];
						geo.z = 10;
						geo.code = feature.attributes['CunCode'];
						geo.name = feature.attributes['CunName'];
						fw[j]=geo;
					}
				   createWaterplantPics();
				}
			}
		}
	}
	function queryError(e) {
		alert(e.error.errorMsg);
	}
	waterplant.getWaterplants = function() {
		myQueryBySQLService.processAsync(queryBySQLParams);
	}
	return waterplant;
}

//bubble创建
function createWaterplantPics() {
	for (var i in fw) {
		addWaterplantPic(fw[i]);
		managerFeature.push(fw[i]);
	}
    //setInterval(updateWaterplantStyles,11000);
}

//创建三维模型
//添加地物到跟踪图层
function addWaterplantPic(p) {
	//创建几何对象
	var geoRegion = new SuperMap.Web.Core.GeoRegion3D();
	var pntWN = new SuperMap.Web.Core.Point3D(p.x + 0.002, p.y + 0.00002, 0);
	var pntEN = new SuperMap.Web.Core.Point3D(p.x - 0.002, p.y + 0.00002, 0);
	var pntES = new SuperMap.Web.Core.Point3D(p.x - 0.002, p.y - 0.00002, 0);
	var pntWS = new SuperMap.Web.Core.Point3D(p.x + 0.002, p.y - 0.00002, 0);
	var point3Ds = new SuperMap.Web.Core.Point3Ds();
	point3Ds.add(pntWN);
	point3Ds.add(pntEN);
	point3Ds.add(pntES);
	point3Ds.add(pntWS);
	geoRegion.addPart(point3Ds);

	//跟踪图层中只能加feature3D，所以这里得把geometry构造成feature3D对象
	var feature3d = new SuperMap.Web.Core.Feature3D();
	feature3d.set_geometry(geoRegion);

	var style3d = new SuperMap.Web.Core.Style3D();

	style3d.set_fillForeColor(new SuperMap.Web.Core.Color(255, 255, 0, 255));
	style3d.set_altitudeMode(SuperMap.Web.Realspace.AltitudeMode.RELATIVE_TO_GROUND);
	style3d.set_extendHeight(100);
	style3d.set_bottomAltitude(50);

	var myUrl = baseWaterplantUrlPrefix+p.code+Math.uuid()+".png";
	var paths=[myUrl,myUrl,myUrl,myUrl];
	style3d.set_sideTextureFiles(paths);
	feature3d.set_style3D(style3d);
	//设置跟踪图层可见
	trackingLayer.set_isVisible(true);
	//将feature3D加入跟踪图层
	trackingLayer.add(feature3d, p.name);
	//scene.get_flyingOperator().flyToBounds(geoRegion.get_bounds());
	return feature3d;
}

/*
//跟新waterplant样式 ，即图片
function updateWaterplantStyles()
{
	for(var i in fw)
	{
		var feature = trackingLayer.get_item(fw[i].name);
		var style  = feature.get_style3D();
		var myUrl = baseWaterplantUrlPrefix+fw[i].code+Math.uuid()+".png";
	    var paths=[myUrl,myUrl,myUrl,myUrl];
		style.set_sideTextureFiles(paths);
	}
	trackingLayer.refresh();
}
 */

